package codetop.dp;


import org.junit.Test;

public class Code042 {
    @Test
    void test(){
        String s=new String("3");
        s.intern();
        String s1="3";
        System.out.println(s==s1);//false
        String s2=new String("3")+new String("3");
        s2.intern();
        String s3="33";
        System.out.println(s2==s3);

    }
    public int trap(int[] height) {
        int []left_max=new int[height.length];
        int []right_max=new int[height.length];
        for (int i = 1; i < height.length; i++) {
            left_max[i]=Math.max(left_max[i-1],height[i-1]);
            right_max[height.length-i-1]=Math.max(right_max[height.length-i],height[height.length-i]);
        }
        int count=0;
        for (int i = 0; i < height.length; i++) {
            int water=Math.max(left_max[i],right_max[i])-height[i];
            count+= Math.max(water, 0);
        }
        return count;
    }
}
